package com.thghh.chinesewordsegmentation;

import com.chenlb.mmseg4j.*;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.io.StringReader;
import java.util.List;
/**
 * Created by 充电了么App - 陈敬雷
 * 充电了么App官网：http://chongdianleme.com/
 * 充电了么App - 专注上班族职业技能提升充电学习的在线教育平台
 * mmseg4j分词功能演示
 */
public class MMSegDemo {
    public static void main(String[] args) {
        String txt = "分布式机器学习实战（人工智能科学与技术丛书）深入浅出，逐步讲解分布式机器学习的框架及应用配套个性化推荐算法系统、人脸识别、对话机器人等实战项目。";
        StringReader input = new StringReader(txt);
        Dictionary dic = Dictionary.getInstance();
        Seg seg = new ComplexSeg(dic);//Complex分词
        //seg = new SimpleSeg(dic);//Simple分词
        MMSeg mmSeg = new MMSeg(input, seg);
        Word word;
        List<String> wordList = Lists.newArrayList();
        try {
            while ((word = mmSeg.next()) != null) {
                //word是单个分出的词，先放到List里下面统一按竖线拼接词打印出来
                wordList.add(word.getString());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            input.close();
        }
        System.out.println(StringUtils.join(wordList.toArray(),"|"));
        /**
         * 输出分词结果：
         分布式|机器|学习|实战|人工智能|科学|与|技术|丛书|深入浅出|逐步|讲解|分布式|机器|学习|的|框架|及|应用|配套|个性化|推荐|算法|系统|人|脸|识别|对话|机器人|等|实战|项目
         */
    }
}